<?PHP

class mvTemplate extends Smarty{

	function __construct(){
		parent::__construct();
		$this->template_dir 	= POMBY_DIR . '/skins/default';
		$this->compile_dir 		= POMBY_DIR . '/cache/smarty/compile';
        $this->config_dir 		= POMBY_DIR . '/skins/default';
        $this->cache_dir 		= POMBY_DIR . '/cache/smarty/cache';
	}

	function page_install($content_tpl){
		$this->assign('content_tpl', $content_tpl);

		if($err = mvError::getErrors())
			$this->assign('mvErrors', $err);

		$this->display('install_shell.tpl');
	}

	function page_title($title){
		$this->assign('page_title', $title);
	}

	function page_display($content_tpl){
		$this->assign('content_tpl', $content_tpl);

		if($err = mvError::getErrors())
			$this->assign('mvErrors', $err);

		$this->_page_constants();
		$this->_page_nav();
		$this->_page_tags();

		$this->display('shell.tpl');
	}

	function _page_nav(){

	}

	function _page_tags(){
		$sql = "SELECT * FROM (SELECT tag, COUNT(*) as cnt FROM tags GROUP BY tag ORDER BY COUNT(*) DESC LIMIT 40) as toptag ORDER BY tag";
		$query = $GLOBALS['db']->prepare_execute($sql);
		$tags = $query->fetchAll();
		// min/max
		$min = 0;
		$max = 1;
		foreach($tags as $v){
			if($v['cnt'] > $max)
				$max = $v['cnt'];
			if($v['cnt'] < $min || $min == 0)
				$min = $v['cnt'];
		}

		// check for all equel tags
		if($min == $max){
			$min = $min - 1;
		}

		// set weight
		foreach($tags as $k => $v){
			$tags[$k]['weight'] = round(($v['cnt'] - $min) / ($max - $min) * 9) + 1;
		}

		$this->assign('tag_list', $tags);
	}

	function _page_constants(){
		$this->assign('kburl', mvSettings::get('kburl'));
		$this->assign('kbname', mvSettings::get('kbname'));
		$this->assign('pluginhtml', mvSettings::get('pluginhtml'));
		$this->assign('pluginpdf', mvSettings::get('pluginpdf'));

		if(isset($_SESSION['user']))
			$this->assign('user', $_SESSION['user']);

		$file= POMBY_DIR . '/docs/VERSION';
		$fhr = fopen("$file", "r");
		$data = fread($fhr,filesize($file)+1);
		fclose ($fhr);
		$version = substr($data,0,6);

		$this->assign('pomby_version', $version);
	}

}

?>